<?php
namespace app\site\service;

/**
 * 标签接口
 */
class LabelService {

	/**
	 * 栏目列表
	 */
	public function nav($data){
        $where = array();

        if(!empty($data['group_id'])){
            $where['group_id'] = $data['group_id'];
        }else {
            $where['group_id'] = 1;
        }

        //上级栏目
        $where['parent_id'] = 0;
        if(isset($data['parent_id'])){
            $where['parent_id'] = $data['parent_id'];
        }
        //其他条件
        if(!empty($data['where'])){
            $where['_sql'] = $data['where'];
        }

        $limit = 10;
        if(!empty($data['limit'])){
            $limit = $data['limit'];
        }

        $list = target('site/SiteNav')->loadList($where, $limit);
        if($list){
            $list = target('site/SiteNav')->getTree($list, $where['parent_id']);
        }
        return $list;
	}

    /**
     * 友情链接
     */
    public function link($data) {
        $where = array();

        if(!empty($data['class_id'])){
            $where['class_id'] = $data['class_id'];
        }else {
            $where['class_id'] = 1;
        }

        if(!empty($data['where'])){
            $where['_sql'] = $data['where'];
        }

        $limit = 10;
        if(!empty($data['limit'])){
            $limit = $data['limit'];
        }

        $list = target('site/SiteLink')->loadList($where, $limit, 'sort asc, link_id asc');
        return $list;
    }

    /**
     * 链接分类
     * @return mixed
     */
    public function linkClass($data) {
        $where = array();

        //上级分类
        if(isset($data['parent_id'])){
            $where['parent_id'] = $data['parent_id'];
        }

        if(!empty($data['where'])){
            $where['_sql'] = $data['where'];
        }

        $limit = 10;
        if(!empty($data['limit'])){
            $limit = $data['limit'];
        }

        $list = target('site/SiteLinkClass')->loadList($where, $limit);
        return $list;
    }

    /**
     * 横幅
     */
    public function banner($data) {
        $where = array();

        if(!empty($data['class_id'])){
            $where['class_id'] = $data['class_id'];
        }else {
            $where['class_id'] = 1;
        }

        if(!empty($data['where'])){
            $where['_sql'] = $data['where'];
        }

        $limit = 10;
        if(!empty($data['limit'])){
            $limit = $data['limit'];
        }

        $list = target('site/SiteBanner')->loadList($where, $limit, 'sort asc, banner_id asc');
        return $list;
    }

    /**
     * 碎片内容
     * @param $data
     * @return mixed
     */
    public function fragment($data) {
        $where = array();
        $where['fragment_id'] = $data['id'];

        if(!empty($data['where'])){
            $where['_sql'] = $data['where'];
        }

        $info = target('site/SiteFragment')->getInfo($data['id']);
        return html_out($info['content']);

    }

}
